package com.inmobi.androidsdk.impl.metric;

import android.content.Context;
import com.inmobi.commons.internal.FileOperations;
import com.inmobi.commons.internal.Log;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;

public class Storage
{
  public static final String FILENAME_IN_CACHE = "inmobi.cache.data";
  public static final String FILENAME_IN_CACHE_EVENTS = "inmobi.cache.data.events.number";
  public static final String FILENAME_IN_CACHE_TS = "inmobi.cache.data.events.timestamp";
  static AtomicBoolean a = new AtomicBoolean(false);
  static AtomicBoolean b = new AtomicBoolean(false);
  private static Context c;
  public static long events = -1L;
  public static long timestamp = -1L;

  private static void a(Context paramContext)
  {
    try
    {
      FileOperations.writeStringToFile(paramContext, "inmobi.cache.data.events.number", "" + events, false);
      FileOperations.writeStringToFile(paramContext, "inmobi.cache.data.events.timestamp", "" + timestamp, false);
      return;
    }
    catch (Exception localException)
    {
      events = 0L;
    }
  }

  public static String readLocalCache(Context paramContext)
  {
    try
    {
      String str = FileOperations.readFileAsString(paramContext, "inmobi.cache.data");
      return str;
    }
    catch (Exception localException)
    {
    }
    return "null,";
  }

  public static void readNumberOfEventsAndTimeStampFromPersistent(Context paramContext)
  {
    c = paramContext;
    if (events != -1L);
    while (true)
    {
      return;
      try
      {
        events = Long.parseLong(FileOperations.readFileAsString(paramContext, "inmobi.cache.data.events.number"));
        timestamp = Long.parseLong(FileOperations.readFileAsString(paramContext, "inmobi.cache.data.events.timestamp"));
        if (timestamp != -1L)
          continue;
        timestamp = System.currentTimeMillis() / 1000L;
        a(c);
        return;
      }
      catch (Exception localException)
      {
        while (true)
          events = 0L;
      }
    }
  }

  public static void resetFile(Context paramContext)
  {
    try
    {
      FileOperations.writeStringToFile(paramContext, "inmobi.cache.data", "", false);
      events = 0L;
      timestamp = System.currentTimeMillis() / 1000L;
      a(paramContext);
      return;
    }
    catch (IOException localIOException)
    {
      Log.internal("InMobiAndroidSDK_3.7.0", "Someting went wrong while saving metrics log to persistent storage", localIOException);
    }
  }

  public static void saveLocalCache(Context paramContext)
  {
    if (!a.compareAndSet(false, true))
      return;
    try
    {
      FileOperations.writeStringToFile(paramContext, "inmobi.cache.data", Queuer.queuer.get(), true);
      events += Queuer.queuer.number;
      Queuer.queuer.reset();
      a(paramContext);
      MetricAction localMetricAction = Logger.action;
      if (localMetricAction == null);
    }
    catch (IOException localIOException)
    {
      try
      {
        Logger.action.fileWritten();
        while (true)
        {
          label66: a.set(false);
          try
          {
            synchronized (a)
            {
              a.notify();
              return;
            }
          }
          catch (Exception localException1)
          {
            Log.internal("InMobiAndroidSDK_3.7.0", "Error saving local cache", localException1);
            return;
          }
          localIOException = localIOException;
          Log.internal("InMobiAndroidSDK_3.7.0", "Someting went wrong while saving metrics log to persistent storage", localIOException);
        }
      }
      catch (Exception localException2)
      {
        break label66;
      }
    }
  }

  public static void saveToLatest()
  {
    saveLocalCache(c);
  }

  // ERROR //
  public static void sendFile(Context paramContext)
  {
    // Byte code:
    //   0: getstatic 40	com/inmobi/androidsdk/impl/metric/Storage:b	Ljava/util/concurrent/atomic/AtomicBoolean;
    //   3: iconst_0
    //   4: iconst_1
    //   5: invokevirtual 112	java/util/concurrent/atomic/AtomicBoolean:compareAndSet	(ZZ)Z
    //   8: ifne +21 -> 29
    //   11: return
    //   12: getstatic 38	com/inmobi/androidsdk/impl/metric/Storage:a	Ljava/util/concurrent/atomic/AtomicBoolean;
    //   15: astore 15
    //   17: aload 15
    //   19: monitorenter
    //   20: getstatic 38	com/inmobi/androidsdk/impl/metric/Storage:a	Ljava/util/concurrent/atomic/AtomicBoolean;
    //   23: invokevirtual 153	java/lang/Object:wait	()V
    //   26: aload 15
    //   28: monitorexit
    //   29: getstatic 38	com/inmobi/androidsdk/impl/metric/Storage:a	Ljava/util/concurrent/atomic/AtomicBoolean;
    //   32: iconst_0
    //   33: iconst_1
    //   34: invokevirtual 112	java/util/concurrent/atomic/AtomicBoolean:compareAndSet	(ZZ)Z
    //   37: ifeq -25 -> 12
    //   40: ldc 99
    //   42: new 47	java/lang/StringBuilder
    //   45: dup
    //   46: invokespecial 48	java/lang/StringBuilder:<init>	()V
    //   49: ldc 155
    //   51: invokevirtual 54	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   54: getstatic 28	com/inmobi/androidsdk/impl/metric/Storage:events	J
    //   57: invokevirtual 57	java/lang/StringBuilder:append	(J)Ljava/lang/StringBuilder;
    //   60: ldc 157
    //   62: invokevirtual 54	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   65: invokevirtual 61	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   68: invokestatic 161	com/inmobi/commons/internal/Log:debug	(Ljava/lang/String;Ljava/lang/String;)V
    //   71: aload_0
    //   72: invokestatic 163	com/inmobi/androidsdk/impl/metric/Storage:readLocalCache	(Landroid/content/Context;)Ljava/lang/String;
    //   75: astore 5
    //   77: new 165	org/json/JSONObject
    //   80: dup
    //   81: invokespecial 166	org/json/JSONObject:<init>	()V
    //   84: astore 6
    //   86: aload_0
    //   87: aload_0
    //   88: invokestatic 172	com/inmobi/androidsdk/bootstrapper/Initializer:getConfigParams	(Landroid/content/Context;)Lcom/inmobi/androidsdk/bootstrapper/ConfigParams;
    //   91: invokevirtual 178	com/inmobi/androidsdk/bootstrapper/ConfigParams:getUID	()Lcom/inmobi/commons/uid/UID;
    //   94: invokestatic 184	com/inmobi/commons/uid/UIDUtil:getMap	(Landroid/content/Context;Lcom/inmobi/commons/uid/UID;)Ljava/util/Map;
    //   97: aload 6
    //   99: invokestatic 188	com/inmobi/commons/uid/UIDUtil:bindToJSON	(Ljava/util/Map;Lorg/json/JSONObject;)V
    //   102: invokestatic 194	java/util/Calendar:getInstance	()Ljava/util/Calendar;
    //   105: astore 7
    //   107: aload 6
    //   109: ldc 196
    //   111: aload 7
    //   113: bipush 15
    //   115: invokevirtual 199	java/util/Calendar:get	(I)I
    //   118: invokevirtual 203	org/json/JSONObject:put	(Ljava/lang/String;I)Lorg/json/JSONObject;
    //   121: pop
    //   122: aload 6
    //   124: ldc 205
    //   126: aload 7
    //   128: invokevirtual 208	java/util/Calendar:getTimeInMillis	()J
    //   131: invokevirtual 211	org/json/JSONObject:put	(Ljava/lang/String;J)Lorg/json/JSONObject;
    //   134: pop
    //   135: aload 6
    //   137: invokevirtual 212	org/json/JSONObject:toString	()Ljava/lang/String;
    //   140: astore 10
    //   142: new 47	java/lang/StringBuilder
    //   145: dup
    //   146: invokespecial 48	java/lang/StringBuilder:<init>	()V
    //   149: aload 10
    //   151: iconst_0
    //   152: iconst_m1
    //   153: aload 10
    //   155: invokevirtual 218	java/lang/String:length	()I
    //   158: iadd
    //   159: invokevirtual 222	java/lang/String:substring	(II)Ljava/lang/String;
    //   162: invokevirtual 54	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   165: ldc 224
    //   167: invokevirtual 54	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   170: ldc 226
    //   172: invokevirtual 54	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   175: aload 5
    //   177: iconst_0
    //   178: iconst_m1
    //   179: aload 5
    //   181: invokevirtual 218	java/lang/String:length	()I
    //   184: iadd
    //   185: invokevirtual 222	java/lang/String:substring	(II)Ljava/lang/String;
    //   188: invokevirtual 54	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   191: ldc 228
    //   193: invokevirtual 54	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   196: ldc 230
    //   198: invokevirtual 54	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   201: invokevirtual 61	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   204: astore 11
    //   206: aload_0
    //   207: invokestatic 172	com/inmobi/androidsdk/bootstrapper/Initializer:getConfigParams	(Landroid/content/Context;)Lcom/inmobi/androidsdk/bootstrapper/ConfigParams;
    //   210: invokevirtual 234	com/inmobi/androidsdk/bootstrapper/ConfigParams:getMetric	()Lcom/inmobi/androidsdk/bootstrapper/MetricConfigParams;
    //   213: invokevirtual 239	com/inmobi/androidsdk/bootstrapper/MetricConfigParams:getUrl	()Ljava/lang/String;
    //   216: aload 11
    //   218: invokestatic 244	com/inmobi/androidsdk/impl/metric/MetricEndPoint:sendData	(Ljava/lang/String;Ljava/lang/String;)V
    //   221: ldc 99
    //   223: new 47	java/lang/StringBuilder
    //   226: dup
    //   227: invokespecial 48	java/lang/StringBuilder:<init>	()V
    //   230: ldc 246
    //   232: invokevirtual 54	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   235: aload_0
    //   236: invokestatic 172	com/inmobi/androidsdk/bootstrapper/Initializer:getConfigParams	(Landroid/content/Context;)Lcom/inmobi/androidsdk/bootstrapper/ConfigParams;
    //   239: invokevirtual 234	com/inmobi/androidsdk/bootstrapper/ConfigParams:getMetric	()Lcom/inmobi/androidsdk/bootstrapper/MetricConfigParams;
    //   242: invokevirtual 239	com/inmobi/androidsdk/bootstrapper/MetricConfigParams:getUrl	()Ljava/lang/String;
    //   245: invokevirtual 54	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   248: invokevirtual 61	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   251: invokestatic 161	com/inmobi/commons/internal/Log:debug	(Ljava/lang/String;Ljava/lang/String;)V
    //   254: aload_0
    //   255: invokestatic 248	com/inmobi/androidsdk/impl/metric/Storage:resetFile	(Landroid/content/Context;)V
    //   258: getstatic 133	com/inmobi/androidsdk/impl/metric/Logger:action	Lcom/inmobi/androidsdk/impl/metric/MetricAction;
    //   261: astore 12
    //   263: aload 12
    //   265: ifnull +11 -> 276
    //   268: getstatic 133	com/inmobi/androidsdk/impl/metric/Logger:action	Lcom/inmobi/androidsdk/impl/metric/MetricAction;
    //   271: invokeinterface 251 1 0
    //   276: getstatic 38	com/inmobi/androidsdk/impl/metric/Storage:a	Ljava/util/concurrent/atomic/AtomicBoolean;
    //   279: iconst_0
    //   280: invokevirtual 141	java/util/concurrent/atomic/AtomicBoolean:set	(Z)V
    //   283: getstatic 38	com/inmobi/androidsdk/impl/metric/Storage:a	Ljava/util/concurrent/atomic/AtomicBoolean;
    //   286: astore_3
    //   287: aload_3
    //   288: monitorenter
    //   289: getstatic 38	com/inmobi/androidsdk/impl/metric/Storage:a	Ljava/util/concurrent/atomic/AtomicBoolean;
    //   292: invokevirtual 144	java/lang/Object:notify	()V
    //   295: aload_3
    //   296: monitorexit
    //   297: getstatic 40	com/inmobi/androidsdk/impl/metric/Storage:b	Ljava/util/concurrent/atomic/AtomicBoolean;
    //   300: iconst_0
    //   301: invokevirtual 141	java/util/concurrent/atomic/AtomicBoolean:set	(Z)V
    //   304: return
    //   305: astore 16
    //   307: aload 15
    //   309: monitorexit
    //   310: aload 16
    //   312: athrow
    //   313: astore 14
    //   315: ldc 99
    //   317: ldc 253
    //   319: invokestatic 161	com/inmobi/commons/internal/Log:debug	(Ljava/lang/String;Ljava/lang/String;)V
    //   322: return
    //   323: astore_1
    //   324: ldc 99
    //   326: ldc 255
    //   328: invokestatic 161	com/inmobi/commons/internal/Log:debug	(Ljava/lang/String;Ljava/lang/String;)V
    //   331: goto -55 -> 276
    //   334: astore 4
    //   336: aload_3
    //   337: monitorexit
    //   338: aload 4
    //   340: athrow
    //   341: astore_2
    //   342: goto -45 -> 297
    //   345: astore 13
    //   347: goto -71 -> 276
    //
    // Exception table:
    //   from	to	target	type
    //   20	29	305	finally
    //   307	310	305	finally
    //   12	20	313	java/lang/Exception
    //   310	313	313	java/lang/Exception
    //   40	263	323	java/lang/Exception
    //   289	297	334	finally
    //   336	338	334	finally
    //   283	289	341	java/lang/Exception
    //   338	341	341	java/lang/Exception
    //   268	276	345	java/lang/Exception
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.inmobi.androidsdk.impl.metric.Storage
 * JD-Core Version:    0.6.2
 */